//
//  NSObject+YYModel.m
//  BTWallet
//
//  Created by 刘军林 on 2018/11/30.
//  Copyright © 2018年 刘军林. All rights reserved.
//

#import "NSObject+YYModel.h"
#import <YYModel.h>

@implementation NSObject (YYModel)

-(id) bt_JSONObject
{
    if ([self isKindOfClass:[NSString class]]) {
        return [NSJSONSerialization JSONObjectWithData:[((NSString *)self) dataUsingEncoding:NSUTF8StringEncoding] options:kNilOptions error:nil];
    } else if ([self isKindOfClass:[NSData class]]) {
        return [NSJSONSerialization JSONObjectWithData:(NSData *)self options:kNilOptions error:nil];
    }
    return [self yy_modelToJSONObject];
}

-(NSData *) bt_JSONData
{
    if ([self isKindOfClass:[NSString class]]) {
        return [((NSString *)self) dataUsingEncoding:NSUTF8StringEncoding];
    } else if ([self isKindOfClass:[NSData class]]) {
        return (NSData *)self;
    }
    return [self yy_modelToJSONData];
}

-(NSString *) bt_JSONString
{
    if ([self isKindOfClass:[NSString class]]) {
        return (NSString *)self;
    } else if ([self isKindOfClass:[NSData class]]) {
        return [[NSString alloc] initWithData:(NSData *)self encoding:NSUTF8StringEncoding];
    }
    return [self yy_modelToJSONString];
}

@end
